package controller;

import entities.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
 
@Controller
public class DefaultController {

    @RequestMapping("/index.htm")
    public String handleIndexGet() {
        return "index"; // forward to view index.jsp
    }
 
    @RequestMapping("/createUser")
    public String hello(@RequestParam(value="name") String name, @RequestParam(value="password") String password, Model model) {
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        return "index";
    }
 
    @RequestMapping("/viewdemo")
    public String demo(ModelMap map) {
        User user = new User();
        user.setName("admin");
        user.setPassword("123456");
        map.put("personObject", user);
        map.addAttribute("helloAgain", "Hello (Again) Spring from Netbeans!!");
        return "demo";
    }
}